<?php
class sampleAdmin extends module {
	public $permissions = array('*'=>array(ROLE_SUPERADMIN));
	public $title = "Sample module with another frame and specified permissions";
	public $frame = "admin";
	
	public function run() {
		$query = 'SELECT
			Code AS "Code",
			Name AS "Name",
			Continent AS "Continent",
			SurfaceArea AS "Surface area (km²)",
			Population AS "Population"
			FROM country WHERE 1';
		new sqlTable($this, $query, $this->engine->getUrlParam(0));
		
		new pagination($this, $this->sql->totalRowsCount, $this->engine->getUrlParam(0));
		
		$continents = array(
			'Asia'=>'Asia',
			'Europe'=>'Europe',
			'North America'=>'North America',
			'Africa'=>'Africa',
			'Oceania'=>'Oceania',
			'Antarctica'=>'Antarctica',
			'South America'=>'South America'
		);
		$form = new formConstructor($this, "just_form", "", _("Form example"));
		
		$form->addField('Code', 'Code', new formString('/^[A-Z]{3}$/'), "3 latin capital character");
		$form->addField('Name', 'Name', new formString('/^[a-z \-]{2,52}$/i'));
		$form->addField('Continent', 'Continent', new formSelectOne($continents));
		$form->addField('SurfaceArea', 'Surface area', new formString('/^[0-9\.]{1,13}$/i'), '(km²)');
		$form->addField(null, 'formSeparator', new formSeparator());
		$form->addField('Population', 'Population', new formString('/^[0-9]{1,11}$/i'));
		$form->addField('CalendarUnixTimestamp', 'CalendarUnixTimestamp', new formCalendarUnixTimestamp());
		$form->addField('CalendarDateTime', 'CalendarDateTime', new formCalendarDateTime());
		$form->addField('formRadio', 'formRadio', new formRadio($continents));
		$form->addField(null, 'Save', new formSubmit());
		if ($form->submit()) {
			if ($form->errors) {
				new pageAlert($this, _("error!"), PAGE_ALERT_ERROR);
			} else {
				new pageAlert($this, $form->getValue('Continent'), PAGE_ALERT_SUCCESS);
			}
			
		}
		$form->write();
	}
}
?>